package c.c.c.a.g;

import android.app.ActivityManager;
import android.content.Context;
import b.i.b.f;
import c.c.c.a.e.a;
import c.c.c.a.i.a.e;
import c.c.c.a.m.b;
import c.c.c.a.n;
import java.util.Objects;
import org.json.JSONObject;

/* compiled from: JavaCrash */
public class c {
    public Context a;

    public c(Context context) {
        this.a = context;
    }

    public void a(long j, Thread thread, Throwable th) {
        boolean z;
        Context context = this.a;
        if (j == 0) {
            j = System.currentTimeMillis();
        }
        a aVar = new a();
        aVar.b("isJava", Integer.valueOf(1));
        aVar.b("event_type", "java_crash");
        aVar.b("timestamp", Long.valueOf(System.currentTimeMillis()));
        aVar.b("data", f.k(th));
        if (th != null) {
            int i = 0;
            while (th != null) {
                try {
                    if (th instanceof OutOfMemoryError) {
                        z = true;
                        break;
                    } else if (i > 20) {
                        break;
                    } else {
                        i++;
                        th = th.getCause();
                    }
                } catch (Throwable unused) {
                }
            }
        }
        z = false;
        aVar.b("isOOM", Boolean.valueOf(z));
        aVar.b("crash_time", Long.valueOf(j));
        aVar.b("process_name", b.f(context));
        String f = b.f(context);
        Object obj = ((f == null || !f.contains(":")) && ((f != null && f.equals(context.getPackageName())) || (f != null && f.equals(context.getApplicationInfo().processName)))) ? 1 : null;
        if (obj == null) {
            aVar.b("remote_process", Integer.valueOf(1));
        }
        JSONObject jSONObject = aVar.a;
        try {
            b.b(jSONObject);
            ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
            if (activityManager != null) {
                b.d(jSONObject, activityManager);
            }
            b.c(jSONObject, activityManager);
        } catch (Throwable unused2) {
        }
        if (thread == null) {
            f = null;
        } else {
            f = thread.getName();
        }
        if (f != null) {
            aVar.b("crash_thread_name", f);
        }
        aVar.b("all_thread_stacks", f.m(f));
        Context context2 = this.a;
        c.c.c.a.f fVar = c.c.c.a.f.JAVA;
        f.p(context2, "java", Thread.currentThread().getName());
        if (e.e != null) {
            a a = e.e.a(fVar, aVar);
            if (c.c.c.a.o.a.b == null) {
                c.c.c.a.o.a.b = new c.c.c.a.o.a(n.a);
            }
            c.c.c.a.o.a aVar2 = c.c.c.a.o.a.b;
            jSONObject = a.a;
            Objects.requireNonNull(aVar2);
            if (jSONObject != null && jSONObject.length() > 0) {
                try {
                    n.c.a();
                    Context context3 = n.a;
                    c.c.c.a.i.c cVar = n.d;
                    f.j(f.g(aVar2.a), String.format("java_%s.npth", new Object[]{String.valueOf(System.nanoTime())}), "http://apmlog.snssdk.com/apm/collect/crash/", jSONObject, true);
                    return;
                } catch (Throwable unused3) {
                    return;
                }
            }
            return;
        }
        throw new IllegalArgumentException("CrashContextAssembly not init");
    }
}
